/**
 * Created by wanthering on 2017/8/16.
 */

const mongoose = require('mongoose');
const Schema = mongoose.Schema;

const LessonSchema = new mongoose.Schema({
  id: Number,
  title: String,
  q1: {
    question:String,
    a:String,
    b:String,
    c:String,
    right:String,
  },
  q2: {
    question:String,
    a:String,
    b:String,
    c:String,
    right:String,
  },
  article: String,
  faceUrl: String,
  giftUrl: String,
  giftName: String,
  deadline: String,
  meta:{
    createAt:{type:Date,default:Date.now()},
    updateAt:{type:Date,default:Date.now()}
  }
});

LessonSchema.pre('save',function(next){
  if(this.isNew){
    this.meta.createAt = this.meta.updateAt = Date.now();
  }else{
    this.meta.updateAt = Date.now();
  }
  next();
});

module.exports = mongoose.model('Lesson',LessonSchema);